#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int mysystem(char *cmd)
{
	int ret=0;
	if(cmd==NULL)
		return -1;
	pid_t pid=fork();
	if(pid==-1)
		return -1;

	if(pid==0){
		char * argv[]={"sh","-c",cmd,NULL};//查看system文档，文档所说
		execvp("/bin/sh",argv);
		exit(127);
	}else {
		int sts;
		waitpid(pid,&sts,0);//不能用wait是因为等指定进程i
		if(WIFEXITED(sts)){
			ret=WEXITSTATUS(sts);
		}else {
			ret=-1;
		}
	}
	return ret;
}
int main()
{
	printf("before\n");
	mysystem("ls -l");
	printf("after\n");
	return 0;
}
